/**
 * 三级联动
 */

var temp;
var P = new Array();
var C = new Array();
var D = new Array();
P = new Array("全校","团总支","阶段","团支部");
C[0] = new Array("全校");
C[1] = new Array("多媒体系","经贸系","计算机系","外语系","数统系","机械系","电气系","物理系","语文系","电话系","传媒系");
C[2] = new Array("1","2","3","4");
C[3] = new Array("多媒体","经贸","计算机","外语","数统","机械","电气","物理","语文","电话","传媒");


for(temp in C)
{
    D[temp] = new Array();
}
D[0][0] = new Array("");
D[1][0] = new Array("");
D[2][1] = new Array("");
for(var i=0;i<10;i++){
	D[3][i] = new Array("");
}
D[3][10] = new Array("11高技计算机网络应,11高技多媒体制作（艺术设计）,11高职计算机应用技术（2）,11高职计算机应用技术（1）,12高技广告制作,12高技计算机网络应用,12高职计算机1,12高职计算机（2）,12高职电子信息工程技术,13高职计算机应用技术（1）,13 3+4开放本科计算机应用（1）,13 3+4开放本科计算机应用（2）,13电子信息工程技术（农业信息管理）,13高职装潢艺术设计,13高技计算机广告制作,13高职计算机应用技术（2）,14开放本科班,14农林高职电子信息,14高职装潢艺术设计班,14高职计算机1班,14高职计算机2,15高职装潢1,15高职装潢2,15高职计算机1,15高职计算机2");

function createCity(sCityName)
{
    var oCity = new Object();
    oCity.province = "";
    oCity.city = sCityName;
    oCity.dist = new Array();
    oCity.pindex = -1;//所属省份在省份数组中的位置index
    oCity.cindex = -1;//城市在所属城市数组中的位置index（二者用来确定区域数组）
   
    var m = -1;var n = -1;
    for(var i = 0; i < C.length; i++)
    {
        for(var j=0; j < C[i].length; j++)
        {
            if(C[i][j] == sCityName)
            {
                oCity.province = P[i];
                oCity.dist = D[i][j];
                oCity.pindex = i;
                oCity.cindex = j;
                break;
            }
        }
       
        if(oCity.province != "")
        {
            break;
        }
    }
   
    return oCity;
}
/*三级、省、市、区域*/
/*面向对象*/
function oMenu(selProvince,selCity,selDist)
{
    ///selProvince省份的select控件id
    ///selCity城市的select控件id
    ///selDist区域的select控件id
    this.oProvince = document.getElementById(selProvince);   
   
    ///城市变化，初始化区域
    function fnInitDist(city)
    {
        var objCity = createCity(city);
        var dist = objCity.dist.toString().split(',');
        ClearSelect(selDist,"请选择");
        InitSelect(selDist,dist,"");
    };
   
    ///初始化城市
    function fnInitCity(province)
    { 
        for(var i = 0;i < P.length;i++)
        {
            if(P[i] == province)
            {
                ClearSelect(selCity,"请选择");
                InitSelect(selCity,C[i],"");
                ClearSelect(selDist,"请选择");
                document.getElementById(selCity).onchange = function (){fnInitDist(this.value);};
                break;
            }
        }       
    };
   
    ///初始化省份
    this.fnInitProvince = function(){
        InitSelect(selProvince,P,"请选择");
        ClearSelect(selCity,"请选择");
        ClearSelect(selDist,"请选择");       
        this.oProvince.onchange = function (){fnInitCity(this.value);};
    };

///初始化select控件
    function InitSelect(obj,aInitValue,sMenu)
    {
        ///obj:要初始化的select控件对象的id
        ///aInitValue:要初始化的数组值
        ///sMenu:在select控件头部要添加的option，value为空；如果该参数为空，则只初始化aInitValue而不加头部
        if(sMenu != "")
        {
            document.getElementById(obj).options.add(new Option(sMenu,""));
        }
       
        for(var i = 0; i < aInitValue.length; i++)
        {
            document.getElementById(obj).options.add(new Option(aInitValue[i],aInitValue[i]));
        }       
    }
   
    function ClearSelect(obj,sMenu)
    {       
        document.getElementById(obj).options.length = 0;
        document.getElementById(obj).options.add(new Option(sMenu,""));       
    }   

}

var oMenu = new oMenu("selProvince","selCity","selDist");//select ID
    oMenu.fnInitProvince();